<?php

class IAction extends IObject {
	private $name;
	private $ret;
	private $prefix = "do";
	private $suffix;
	
	public function __construct($name) {
		$this->name = $name;
	}
	
	public function setName($name) {
		$this->name = $name;
	}
	
	public function setRet($ret) {
		$this->ret = $ret;
	}
	
	public function name() {
		return $this->name;
	}
	
	public function ret() {
		return $this->ret;
	}
	
	public function setPrefix($prefix) {
		if (!IVM::singleton()->isValidVariableName($prefix)) {
			throw new IException("error action prefix '{$prefix}'");
		}
		$this->prefix = $prefix;
	}
	
	public function setSuffix($suffix) {
		if (!IVM::singleton()->isValidVariableName($suffix)) {
			throw new IException("error action suffix '{$suffix}'");
		}
		$this->suffix = $suffix;
	}
	
	public function method() {
		return $this->prefix . $this->name . $this->suffix;
	}
	
	/**
	 * Enter description here...
	 *
	 * $pattern:
	 *   *
	 *   add,modify,delete
	 *   array("add.modify", "delete")
	 *   array(array("add", "modify"), "delete")
	 * 
	 * @param unknown_type $filter
	 */
	public function match($pattern) {
		if ($pattern == "*") {
			return true;
		}
		if (is_string($pattern)) {
			$patterns = explode(".", $pattern);
			return in_array($this->name, $patterns);
		}
		if (is_array($pattern)) {
			$patterns = array();
			foreach ($pattern as $value) {
				if (is_string($value) && strstr(".", $value)) {
					$_patterns = explode(".", $value);
					foreach ($_patterns as $_pattern) {
						$patterns[] = $pattern;
					}
				}
				elseif (is_string($value)) {
					$patterns[] = $value;
				}
				elseif (is_array($value)) {
					foreach ($value as $_pattern) {
						$patterns[] = $pattern;
					}
				}
			}
			return in_array($this->name, $patterns);
		}
		return false;
	}
}

?>